package com.example.mapdata.controller;

import com.example.mapdata.vo.ResultVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@CrossOrigin
public class SesionController {

    @GetMapping("/find_sesion")
    public ResultVo findSesion(HttpSession session, @RequestBody Map map) {
        String name = (String) map.get("name");
        String value = (String) map.get("value");

        //设置session中的数据
        session.setAttribute(name, value);
        return new ResultVo("设置成功", true);
    }

    @GetMapping("/get_sesion")
    public ResultVo sesion(HttpServletRequest request, @RequestBody String name) {
        HttpSession session = request.getSession();
        Object loginUser = session.getAttribute(name);
        return new ResultVo(200, "获取成功", true, loginUser);
    }
}
